﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace QDP.Platform.Silverlight.Controls
{
    [TemplatePart(Name = PART_Title, Type = typeof(TextBlock))]
    [TemplatePart(Name = PART_Thumbnail, Type = typeof(Image))]
    public class WindowIcon : Button
    {
        // Template parts
        private const string PART_Title = "Title";
        private const string PART_Thumbnail = "Thumbnail";

        // VSM states
        private const string VSMSTATE_StateNormal = "Normal";
        private const string VSMSTATE_StateMouseOver = "MouseOver";

        public string Title { get; set; }

        public ImageSource Thumbnail { get; set; }

        public Widget Window { get; set; }

        private bool selected;
        public bool Selected
        {
            get
            {
                return selected;
            }

            set
            {
                selected = value;
                VisualStateManager.GoToState(
                    this,
                    value ? VSMSTATE_StateMouseOver : VSMSTATE_StateNormal, 
                    true);
            }
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

           var title = GetTemplateChild(PART_Title) as TextBlock;
           var thumbnail = GetTemplateChild(PART_Thumbnail) as Image;

            title.Text = Title;
            thumbnail.Source = Thumbnail;
        }
    }
}
